/**
 * Created by baiguiren on 1/23/17.
 */

let async = require('async');

let count = 0;

//callback在循环完成之后才会调用
async.whilst(
  function () {
    return count < 5;
  },
  function (callback) {
    count++;
    setTimeout(function () {
      callback(null, count);
    }, 1000);
  },
  function (err, n) {
    // 5 seconds have passed, n = 5
    console.log(n);
  }
);